package com.ruoyi.hospital.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.hospital.domain.YlDepartment;
import com.ruoyi.hospital.mapper.YlAreaMapper;
import com.ruoyi.hospital.mapper.YlDepartmentMapper;
import com.ruoyi.hospital.mapper.YlDoctorMapper;
import com.ruoyi.hospital.service.IYlDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 科室信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-02-16
 */
@Service
public class YlDepartmentServiceImpl implements IYlDepartmentService
{
    @Autowired
    private YlDepartmentMapper ylDepartmentMapper;

    @Autowired
    private YlAreaMapper ylAreaMapper;

    /**
     * 查询科室信息
     * 
     * @param departmentId 科室信息主键
     * @return 科室信息
     */
    @Override
    public YlDepartment selectYlDepartmentByDepartmentId(Long departmentId)
    {
        return ylDepartmentMapper.selectYlDepartmentByDepartmentId(departmentId);
    }

    /**
     * 查询科室信息
     *
     * @param superId 科室信息主键
     * @return 科室信息
     */
    @Override
    public YlDepartment selectYlDepartmentByDepartmentId2(Long superId)
    {
        return ylDepartmentMapper.selectYlDepartmentByDepartmentId2(superId);
    }

    /**
     * 查询科室信息列表
     * 
     * @param ylDepartment 科室信息
     * @return 科室信息
     */
    @Override
    public List<YlDepartment> selectYlDepartmentList(YlDepartment ylDepartment)
    {
        List<YlDepartment> ylDepartmentList = ylDepartmentMapper.selectYlDepartmentList(ylDepartment);

        for (int i = 0; i < ylDepartmentList.size(); i++) {
            if(ylDepartmentList.get(i).getSuperId()==0) {
                ylDepartmentList.get(i).setSuperName(ylDepartmentList.get(i).getName());
            } else {
                ylDepartmentList.get(i).setSuperName(ylDepartmentMapper.selectYlDepartmentByDepartmentId(ylDepartmentList.get(i).getSuperId()).getName());
            }
            ylDepartmentList.get(i).setAreaName(ylAreaMapper.selectYlAreaByAreaId(ylDepartmentList.get(i).getAreaId()).getName());
        }
        return ylDepartmentList;
    }

    /**
     * 新增科室信息
     * 
     * @param ylDepartment 科室信息
     * @return 结果
     */
    @Override
    public int insertYlDepartment(YlDepartment ylDepartment)
    {
        ylDepartment.setCreateTime(DateUtils.getNowDate());
        return ylDepartmentMapper.insertYlDepartment(ylDepartment);
    }

    /**
     * 修改科室信息
     * 
     * @param ylDepartment 科室信息
     * @return 结果
     */
    @Override
    public int updateYlDepartment(YlDepartment ylDepartment)
    {
        ylDepartment.setUpdateTime(DateUtils.getNowDate());
        return ylDepartmentMapper.updateYlDepartment(ylDepartment);
    }

    /**
     * 批量删除科室信息
     * 
     * @param departmentIds 需要删除的科室信息主键
     * @return 结果
     */
    @Override
    public int deleteYlDepartmentByDepartmentIds(Long[] departmentIds)
    {
        return ylDepartmentMapper.deleteYlDepartmentByDepartmentIds(departmentIds);
    }

    /**
     * 删除科室信息信息
     * 
     * @param departmentId 科室信息主键
     * @return 结果
     */
    @Override
    public int deleteYlDepartmentByDepartmentId(Long departmentId)
    {
        return ylDepartmentMapper.deleteYlDepartmentByDepartmentId(departmentId);
    }

    @Override
    public List<YlDepartment> selectAll() {
        return ylDepartmentMapper.selectAll();
    }

    @Override
    public List<YlDepartment> selectYlDepartmentBySuperID(Long superId) {
        return ylDepartmentMapper.selectYlDepartmentBySuperID(superId);
    }
}
